home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Magazine / Morphos / GCC / ppc-amigaos / include / sys / file.h < prev    next >
C/C++ Source or Header  |  1998-04-18  |  5KB  |  137 lines

  1. /*
  2.  *  This file is part of ixemul.library for the Amiga.
  3.  *  Copyright (C) 1991, 1992  Markus M. Wild
  4.  *
  5.  *  This library is free software; you can redistribute it and/or
  6.  *  modify it under the terms of the GNU Library General Public
  7.  *  License as published by the Free Software Foundation; either
  8.  *  version 2 of the License, or (at your option) any later version.
  9.  *
  10.  *  This library is distributed in the hope that it will be useful,
  11.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13.  *  Library General Public License for more details.
  14.  *
  15.  *  You should have received a copy of the GNU Library General Public
  16.  *  License along with this library; if not, write to the Free
  17.  *  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  */
  19.  
  20. #ifndef _SYS_FILE_H
  21. #define _SYS_FILE_H
  22.  
  23. #include <sys/types.h>
  24. #include <sys/fcntl.h>
  25. #include <sys/unistd.h>
  26.  
  27. #ifdef _INTERNAL_FILE
  28. #include <sys/stat.h>
  29. #include <libraries/dosextens.h>
  30.  
  31. /* this is the incore representation of a DTYPE_MEM file */
  32. struct mem_file {
  33.   int   mf_offset;
  34.   void *mf_buffer;
  35. };
  36.  
  37. /* this `glue' makes a tty a subtype of a plain file. Ie f->f_fh will work
  38.    for plain files as well as ttys. */
  39. struct tty_glue {
  40.   struct FileHandle *fh;
  41.   unsigned long ttyflags;       /* ixemul mapping of termios flags */
  42. };                /* if we run out of bits, we should */
  43.                 /* allocate a tty structure instead */
  44.  
  45. /* ixemul termios flag mappings: */
  46. #define IXTTY_INLCR        0x00000001
  47. #define IXTTY_ICRNL        0x00000002
  48. #define IXTTY_OPOST        0x00000004
  49. #define IXTTY_ONLCR        0x00000008
  50. #define IXTTY_RAW        0x00000010
  51. #define IXTTY_PKT        0x00000020  /* TIOCPKT replacement */
  52.  
  53. /* this will hold basic information about a file, but contrairy to
  54.  * Unix, it will also hold its name */
  55.  
  56. struct file {
  57.   char *f_name;         /* the name as used with open() */
  58.   int f_stb_dirty,   /* gets == 1, if changes have been made to 'stb' */
  59.       f_type,         /* can be a file or some amiga..devices */
  60.       f_flags,         /* see fcntl.h */
  61.       f_count,         /* open-count, normally 1, higher after dup() */
  62.       (*f_write)(),    /* functions to perform write,read,etc on this fd */
  63.       (*f_read)(),
  64.       (*f_ioctl)(),
  65.       (*f_select)(),
  66.       (*f_close)();
  67.   union {
  68.     struct FileHandle *fh; /* this is a CPTR to the allocated
  69.                 * FileHandle */
  70.     struct mem_file mf;       /* current data for incore files */
  71.     struct {
  72.       int so;        /* points to socket when DTYPE_SOCKET */
  73.     int domain;
  74.     int type;
  75.     int protocol;
  76.     long id;       /* used in vfork() to store id of socket to give to child */
  77.     } inetsock;
  78.     struct unix_socket *sock; /* points to AF_UNIX socket - DTYPE_USOCKET */
  79.     struct sock_stream *ss;
  80.     struct tty_glue tg;
  81.   } f__fh;
  82. #define f_fh  f__fh.fh
  83. #define f_mf  f__fh.mf
  84. #define f_so  f__fh.inetsock.so
  85. #define f_socket_domain f__fh.inetsock.domain
  86. #define f_socket_type f__fh.inetsock.type
  87. #define f_socket_protocol f__fh.inetsock.protocol
  88. #define f_socket_id f__fh.inetsock.id
  89. #define f_sock    f__fh.sock
  90. #define f_ss  f__fh.ss
  91. #define f_ttyflags f__fh.tg.ttyflags
  92.   /* WARNING: if you change this struct, take care, that f_sp starts at
  93.    * long (!) alignment in the struct. The file-table will be allocated
  94.    * by AllocMem(), thus by itself it will have DOS-compatible alignment,
  95.    * if you don't follow this, you'll get some nice gurus.. */
  96. #ifdef __pos__
  97.   struct pOS_TimeVal f_tv;
  98.   struct pOS_DosIOReq f_select_sp;
  99. #else
  100.   struct StandardPacket f_sp; /* all IO is done thru the Packet-Interface,
  101.                    * not the higher-level DOS-functions */
  102.   struct StandardPacket f_select_sp; /* for the select() function */
  103. #endif
  104.   struct stat f_stb;    /* file-params at open-time, or after changes to fd */
  105.   int    f_sync_flags;    /* for process synchronization */
  106. };
  107.  
  108.  
  109. #define FSFB_LOCKED    (0)
  110. #define FSFF_LOCKED    (1<<0)    /* means the fh is in use */
  111. #define FSFB_WANTLOCK    (1)
  112. #define FSFF_WANTLOCK    (1<<1)    /* means a process is sleeping on fh to get free */
  113.  
  114. #define FSDB_MODE       (0)
  115. #define FSDF_MODE       (1<<0)  /* means fchmod() was used on the file */
  116. #define FSDB_OWNER      (1)
  117. #define FSDF_OWNER      (1<<1)  /* means fchown() was used on the file */
  118. #define FSDB_UTIME      (2)
  119. #define FSDF_UTIME      (1<<2)  /* means we have to set the file time ourselves */
  120.                                 /* this is only needed if we truncate the file
  121.                                    without writing anything to it.
  122.                                    Example: echo -n >foo */
  123.  
  124. #endif /* _INTERNAL_FILE_H */
  125.  
  126.  
  127. #define DTYPE_FILE    1    /* 'file' is really a file */
  128. #define DTYPE_PIPE    2    /* it's an incore pipe */
  129. #define DTYPE_MEM    3    /* a RDONLY file completely buffered in memory */
  130. #define DTYPE_TASK_FILE    4    /* is a 'file', but used by a task, not a process !*/
  131. #define DTYPE_SOCKET    5    /* socket (inet.library interface) */
  132. #define DTYPE_USOCKET    6    /* socket (own socket code) */
  133. #define DTYPE_TTY    7    /* AmigaOS file, with special access functions */
  134. /* more to follow.. */
  135.  
  136. #endif /* _SYS_FILE_H */
  137.